﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FirstGame.Objects
{
    public class Player : MovingObject
    {
        public Player(Texture2D sprite, Vector2 position, Vector2 speed)
        {
            Sprite = sprite;
            Position = new Vector2(position.X - sprite.Width/2, position.Y - sprite.Height/2);
            Speed = speed;
            SetBoundingBox();
        }

        public void UpdatePlayer(Coords min, Coords max)
        {
            UpdateObject();
            IsPlayerAtBoundary(min, max);
        }

        private void IsPlayerAtBoundary(Coords min, Coords max)
        {
            
            float positionX = Position.X;
            float positionY = Position.Y;
            if (positionX > max.X)
            {
                Position = new Vector2(max.X, positionY);
            }

            else if (positionX < min.X)
            {
                Position = new Vector2(min.X, positionY);
            }

            if (positionY > max.Y)
            {
                Position = new Vector2(positionX, max.Y);
            }

            else if (positionY < min.Y)
            {
                Position = new Vector2(positionX, min.Y); ;
            }
        }
    }
}
